<!DOCTYPE html>
<html>

	<head>
		<title>OpenAuth.net官方网站 - 最好用的.net权限工作流框架|.net core快速开发框架|.net core权限管理|.net core工作流</title>
  		<meta name="Keywords" content="openauth.net,.net开源工作流,.NET开源权限管理">
  		<meta name="Description" content="最好用的.net开源工作流框架,最好用的.NET开源权限管理框架">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<link rel="stylesheet" href="../../css/element-ui.css">
		<link href="../../font/css/font-awesome.min.css" rel="stylesheet">
		<link rel="stylesheet" href="../../css/common.css">
	</head>

	<body>
		<div id="app" v-cloak>
			<el-container>
				<el-header class="box-flex align-center">
					<app-header :current="current"></app-header>
				</el-header>
				<el-main>
					<div class="container m-t-lllg">
						<el-card class="login" shadow="never">
							<el-tabs v-model="activeName">
								<el-tab-pane label="登陆" name="login">
									<el-form label-width="100px" :model="login" ref="login" :rules="rules">
										<el-form-item label="邮箱" prop="account">
											<el-input class="w-300" v-model="login.account" clearable></el-input>
										</el-form-item>
										<el-form-item label="密码" prop="pwd">
											<el-input class="w-300" v-model="login.pwd" clearable type="password"></el-input>
										</el-form-item>
										<el-form-item>
											<el-button type="primary" @click="onlogin">立即登陆</el-button>
										</el-form-item>
									</el-form>
								</el-tab-pane>
								<el-tab-pane label="注册" name="register">
									<el-form label-width="100px" :model="register" ref="register" :rules="gisterRules">
										<el-form-item label="邮箱" prop="account">
											<el-input class="w-300" v-model="register.account" clearable></el-input>
										</el-form-item>
										<el-form-item label="用户名" prop="name">
											<el-input class="w-300" v-model="register.name" clearable></el-input>
										</el-form-item>
										<el-form-item label="密码" prop="pwd">
											<el-input class="w-300" type="password" v-model="register.pwd" clearable placehoder="6-16位"></el-input>
										</el-form-item>
										<el-form-item label="确认密码" prop="checkPass">
											<el-input class="w-300" type="password" v-model="register.checkPass" clearable></el-input>
										</el-form-item>
										<el-form-item>
											<el-button type="primary" @click="onRegister">立即注册</el-button>
										</el-form-item>
									</el-form>
								</el-tab-pane>
							</el-tabs>
						</el-card>
					</div>

				</el-main>
				<el-footer height="100px">
					<app-footer></app-footer>
				</el-footer>
			</el-container>
		</div>

	</body>
	<!-- import Vue before Element -->
	<script src="../../js/vue.js"></script>

	<!-- import JavaScript -->
	<script src="../../js/element-ui.js"></script>
	<script src="../../js/axios.js"></script>
	<script src="../../js/header.js"></script>
	<script src="../../js/footer.js?v=2"></script>
	<script src="../../js/common.js"></script>
	<script>
		new Vue({
			data() {
				var validatePass2 = (rule, value, callback) => {
					if(value === '') {
						callback(new Error('请再次输入密码'));
					} else if(value !== this.register.pwd) {
						callback(new Error('两次输入密码不一致!'));
					} else {
						callback();
					}
				}
				return {
					current: 'login',
					activeName: '',
					login: {},
					register: {},
					rules: {
						account: [{
							required: true,
							message: '用户名不能为空',
							trigger: 'blur'
						}],
						pwd: [{
							required: true,
							message: '密码不能为空',
							trigger: 'blur'
						}]
					},
					gisterRules: {
						account: [{
							required: true,
							message: '用户名不能为空',
							trigger: 'blur'
						}],
						name: [{
							required: true,
							message: '用户名不能为空',
							trigger: 'blur'
						}],
						pwd: [{
							min: 6,
							max: 16,
							required: true,
							message: '密码为6-16位',
							trigger: 'blur'
						}],
						checkPass: [{
							validator: validatePass2,
							trigger: 'blur'
						}]
					}
				}
			},
			created() {
				this.activeName = 'login'
				this.current = 'login'
				var current = GetQueryString('current')
				if(current && current !=''){
					this.activeName = 'register'
					this.current = 'register'
				}
			},
			methods: {
				onlogin() {
					this.$refs['login'].validate((valid) => {
						if(valid) {
							var postData = this.login
							service({
								url: '/user/login',
								method: 'post',
								data: postData,
							}).then((res) => {
								if(res.code !== 200) {
									this.$notify.error({
										title: '错误',
										message: res.message
									})
									return
								}
								sessionStorage.token = res.data
								service({
									url: '/user/getLoginUser',
									method: 'get',
								}).then((res) => {
									if(res.code !== 200) {
										this.$notify.error({
											title: '错误',
											message: res.message
										})
										return
									}
									this.$notify.success({
										title: '登陆成功',
									})
									sessionStorage.user =JSON.stringify(res.data);
									sessionStorage.isLogin = true
									setTimeout(function() {
										if(history.length > 3) {
											history.go(-1)
										} else {
											window.location.href = "../question/index.html"
										}
									}, 1000)
								})
							})
						} else {
							this.$notify.error({
								title: '错误',
								message: '请正确填写用户名和密码'
							});
							return false;
						}
					});
				},
				onRegister() {
					this.$refs['register'].validate((valid) => {
						if(valid) {
							var postData = this.register
							service({
								url: '/user/addUser',
								method: 'post',
								data: postData,
							}).then((res) => {
								if(res.code !== 200) {
									this.$notify.error({
										title: '错误',
										message: res.message
									})
									return
								}
								this.$notify.success({
									title: '注册成功',
								})
								setTimeout(function() {
									if(history.length > 3) {
										history.go(-1)
									} else {
										window.location.href = "../question/index.html"
									}
								}, 1000)
							})
						} else {
							this.$notify.error({
								title: '错误',
								message: '请正确填写用户名和密码'
							});
							return false;
						}
					});
				}
			}
		}).$mount('#app')
	</script>

</html>